package com.jahepi.android.componente;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.view.View.OnClickListener;

import com.jahepi.android.R;

public class TecladoNumerico extends LinearLayout implements OnClickListener, TecladoNumericoInterface {
	
	private static String TAG = "TecladoNumerico";
	private Button button1, button2, button3, button4, button5;
	
	public TecladoNumerico(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		setOrientation(HORIZONTAL);
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.tecladonumerico, this);
        
        button1 = (Button) findViewById(R.id.button01);
        button2 = (Button) findViewById(R.id.button02);
        button3 = (Button) findViewById(R.id.button03);
        button4 = (Button) findViewById(R.id.button04);
        button5 = (Button) findViewById(R.id.button05);
        
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);
        button5.setOnClickListener(this);
	}

	public void onClick(View v) {
		Button button = (Button) v;	
		int i = Integer.parseInt(button.getText().toString());
		i++;
		if(i > 9) {
			i = 0;
		}
		button.setText(Integer.toString(i));
	}
	
	public int obtenerNumero() {
		String n1 = button1.getText().toString();
		String n2 = button2.getText().toString();
		String n3 = button3.getText().toString();
		String n4 = button4.getText().toString();
		String n5 = button5.getText().toString();
		
		String n = n1 + n2 + n3 + n4 + n5;
		Log.d(TAG, "Numero: " + n);
		return Integer.parseInt(n);
	}
}
